package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
import ngames.com.sushitv.R;
import ngames.com.sushitv.base.BaseListAdapter;
import ngames.com.sushitv.entity.ItemVideo;

/**
 * Created by edmond on 16-8-9.
 */
public class FavoriteAdapter extends BaseListAdapter<ItemVideo> {
    private Context context;
    private ArrayList<ItemVideo> videoList;
    private LayoutInflater inflater;
    private boolean isShow = false;

    public FavoriteAdapter(Context context, ArrayList<ItemVideo> videoList){
        super(context,videoList);
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(inflater.inflate(R.layout.item_favorite,parent,false));
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        if(isShow){
            ((ViewHolder)holder).imageView.setVisibility(View.VISIBLE);
            ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.setData(position);
        }else{
            ((ViewHolder)holder).imageView.setVisibility(View.GONE);
        }
    }

    public void setShow(){
        isShow = true;
        notifyDataSetChanged();
    }

    public void setHide(){
        isShow = false;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if(mDataList.size()<12) {
            return mDataList.size();
        }else{
            return 12;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private Boolean isSelect=false;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.select);

        }

        public void setData(int data) {
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(isSelect){
                        imageView.setImageResource(R.drawable.ico_wx);
                        isSelect=false;
                    }else {
                        imageView.setImageResource(R.drawable.ico_xz);
                        isSelect=true;
                    }
                }
            });
        }
    }
}
